<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
        <link rel="stylesheet" href="../css/orderset.css">
        <!-- 引入组件库 -->
        <script src="../js/vue.js"></script>
        <script src="../plugins/elementui/index.js"></script>
        <script type="text/javascript" src="../js/jquery.min.js"></script>
        <link rel="stylesheet" href="../css/style.css">
        <script src="../plugins/echarts/echarts.js"></script>
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>统计分析<small>会员数量</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>统计分析</el-breadcrumb-item>
                    <el-breadcrumb-item>会员数量</el-breadcrumb-item>

                </el-breadcrumb>
            </div>
            <div class="app-container">

                <div class="box">
                    <div id="app" >
                        <el-date-picker
                                ref="datesRef"
                                type="dates"
                                v-model="dateArr"
                                :editable = "false"
                                format="yyyy-MM-dd"
                                value-format="yyyy-MM-dd"
                                placeholder="选择一个或多个日期">
                        </el-date-picker>
                        <el-button type="primary" @click="clickBtn" class="btn">选择时间</el-button>
                    </div>

                    <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
                    <div id="chart1" style="height:500px;">

                    </div>
                </div>
            </div>
        </div>
    </body>
    <!-- 引入组件库 -->
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <script type="text/javascript">
        new Vue({
            el: "#app",
            data: {
                monthValue : "2018-06",
                dateArr: [],
                printStr: ""
            },
            methods: {
                clickBtn: function () {
                    // alert(this.dateArr)
                    axios.get("http://localhost:82/report/getMemeberReportByDate.do?date="+this.dateArr).then((res)=>{
                        myChart1.setOption(
                            {
                                title: {
                                    text: '会员数量'
                                },
                                tooltip: {},
                                legend: {
                                    data:['会员数量']
                                },
                                xAxis: {
                                    data: res.data.data.months
                                },
                                yAxis: {
                                    type:'value'
                                },
                                series: [{
                                    name: '会员数量',
                                    type: 'line',
                                    data: res.data.data.memberCount
                                }]
                            });
                    });
                }
            },
            mounted: function(){
                //为了解决bug，所以默认值放在了这里
                this.$nextTick(function(){
                    this.$refs.datesRef.showPicker();
                    this.$refs.datesRef.hidePicker();
                });
            }
        });
        // 基于准备好的dom，初始化echarts实例
        var myChart1 = echarts.init(document.getElementById('chart1'));

        // 使用刚指定的配置项和数据显示图表。
        //myChart.setOption(option);
        /**
         * months: 最近一年的月份 类型：集合或者数组
         * memberCount: 每个月的会员数量， 类型： 集合或者数组
         *
         * controller： 返回map
         * map 两个key
         *      months: 集合
         *      memberCount:集合
         *
         *      {
         *          months： [2019-08,2019-09],
         *          memberCount: [1, 6]
         *      }
         *
         */
        axios.get("http://localhost:82/report/getMemberReport.do").then((res)=>{
            myChart1.setOption(
                                {
                                    title: {
                                        text: '会员数量'
                                    },
                                    tooltip: {},
                                    legend: {
                                        data:['会员数量']
                                    },
                                    xAxis: {
                                        data: res.data.data.months
                                    },
                                    yAxis: {
                                        type:'value'
                                    },
                                    series: [{
                                        name: '会员数量',
                                        type: 'line',
                                        data: res.data.data.memberCount
                                    }]
                                });
        });
    </script>
</html>
